package org.factoryMethod.lazy;

import java.util.HashMap;

public class ProductFactory{
	private static final HashMap<String, Product> pool = new HashMap<String, Product>();
	private static synchronized Product createProduct(String key){
		Product product = null;
//		如果Map中已有对象
		if(pool.containsKey(key)){
			product = pool.get(key);
		}
		else{
			if(key.equals("ConcreteProduct1")){
				product = new ConcreteProduct1();
			}
			else{
				product = new ConcreteProduct2();
			}
			pool.put(key, product);
		}
		return product;
	}
}
